{template '_header'}
{php $this->followBar()}
<link rel="stylesheet" href="../addons/ewei_shopv2/plugin/creditshop/template/mobile/default/images/common.css" />
<link rel="stylesheet" href="../addons/ewei_shopv2/plugin/creditshop/static/css/common.css" />
<!-- <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.js"></script> -->
<style type="text/css">
    .fui-navbar ~ .fui-content, .fui-content.navbar{padding-bottom:0;}
    {if $set['creditbalance']==0 && $pay['credit'] == 0}
    .fui-actionsheet a.balance{display: none;}
    {/if}
    {if $set['creditwechat']==0 && $pay['weixin'] == 0 && $pay['weixin_jie'] == 0}
    .fui-actionsheet a.wechat{display: none;}
    {/if}
    {if $set['creditalipay']==0 && $pay['alipay'] == 0}
    .fui-actionsheet a.alipay{display: none;}
    {/if}
    .text-danger2 {
        background: none;
    }
    #msg_box{    
        position: fixed;
        background: #000;
        width: 400xp;
        height: 60px;
        color: #FFF;
        z-index: 100;
        left: 20%;
        top: 15%;
        line-height: 25px;
        padding: 20px;
        text-align: center;
        border-radius: 5px;
        opacity: 0.5;
    }
</style>
<style type="text/css">
    .cut_num, .add_num{
        width: 1.1rem;
        line-height: 1.1rem;
        /*display: flex; */
        align-items: center; 
        justify-content: center; 
        font-size: .65rem;
        color: #666;
        background: #fff;
        height: inherit;
        font-weight: bold;
        position: relative;
        text-align: center;
        z-index: 1;
    }
    .number .num{
        -webkit-box-flex: 1;
        -webkit-flex: 1;
        -ms-flex: 1;
        flex: 1;
        overflow: hidden;
        line-height: inherit;
        color: #666;
        text-align: center;
        border: 0;
        font-size: .7rem;
        width: 20px;
    }
    #total, .total_num{
        color: red;
    }
    .msg{
        color:red;
        text-align: center;
        float: right;
    }
</style>
<div class='fui-page order-detail-page'>
    <div class="fui-header">
        <div class="fui-header-left">
            <a class="back" href="{php echo mobileUrl('creditshop/detai')}"></a>
        </div>
        <div class="title">创建订单</div>
        <div class="fui-header-right"></div>
    </div>
    <div class='fui-content navbar'>
        <!-- {if $goods['type']==0}
            <div class="fui-cell-group fui-cell-click">
                {if $goods['isverify']==0 && $goods['goodstype']==0}
                <div class="fui-cell ">
                    <div class="fui-cell-label ">收货地址</div>
                    <a class="fui-cell-info" href="{php echo mobileUrl('member/address/selector')}">
                        <div class="fui-cell-remark" id="address_select">请选择收货地址</div>
                    </a>
                </div>
                {/if}
            </div>
        {/if} -->

        <!-- 门店信息 -->
        {if !empty($belong_mendian) && $set['is_use'] == '1' && $setting['is_show_mendian_info'] == 1}
        <div class="fui-cell-group">
            <div class="fui-cell must ">
                <div class="fui-cell-label ">享受权益<br/>线下地址</div>
                <div class="fui-cell-info" style="word-wrap:break-word;white-space: normal;">{$belong_mendian['area']}{$belong_mendian['address']}</div>
            </div>
        </div>
        <div class="fui-cell-group">
            <div class="fui-cell must ">
                <div class="fui-cell-label ">门店电话</div>
                <div class="fui-cell-info">{$belong_mendian['mobile']} - {$belong_mendian['username']}</div>
            </div>
        </div>
        <div class="fui-cell-group">
            <div class="fui-cell must ">
                <div class="fui-cell-label ">门店名称</div>
                <div class="fui-cell-info">{$belong_mendian['title']}</div>
            </div>
        </div>
        {/if}


        <div class="fui-list-group goods-list-group">
            <div class="fui-list-group-title">
                <i class="icon icon-shop"></i>{$account['name']}
                {if !empty($message)}<span class="msg">{$message}</span>{/if}
            </div>
                {loop $goods_list $goods}
                <input type='hidden' name='goodsid[]' value="{$goods['id']}" />
                <input type='hidden' name='optionid[]' value="{$goods['optionid']}" />
                <div class="fui-list goods-item align-start">
                    {if $setting['show_type'] == 1}
                    <div class="fui-list-media">
                        <a href="{php echo mobileUrl('identity/list/detail',array('id'=>$goods['goodsid']))}">
                            <img id="" class="round" src="{php echo tomedia($goods['thumb'])}">
                        </a>
                    </div>
                    {/if}
                    <div class="fui-list-inner">
                        <a href="{php echo mobileUrl('identity/list/detail',array('id'=>$goods['goodsid']))}">
                            <div class="subtitle">
                                {if $goods['seckillinfo'] && $goods['seckillinfo']['status']==0}<span class='fui-label fui-label-danger'>{$goods['seckillinfo']['tag']}</span>{/if}
                                {if empty($goods['isnodiscount']) && !empty($goods['dflag'])}<span class='fui-label fui-label-danger'>折扣</span>{/if}
                                {if $goods['type']==4}<span class='fui-label fui-label-danger'>批发</span>{/if}
                                {$goods['title']}{if !empty($goods['useful_time'])}(有效期{$goods['useful_time']}){/if}
                            </div>
                            {if !empty($goods['optionid'])}
                            <div class="text ">
                                {$goods['optiontitle']}{$goods['id']}
                            </div>
                            {/if}

                        </a>
                    </div>
                    <div class="fui-list-angle"style="width: auto">
                        <span style="font-size: .65rem;color: #000">￥<span class="marketprice">{if $goods['marketprice'] > $goods['unitprice']}{php echo price_format($goods['marketprice'],2)}{else}{php echo price_format($goods['marketprice'],2)}{/if}</span></span>
                        <div class="num">
                            <div class="number" data-num="{php echo price_format($goods['marketprice'],2)}" data-goodsid="{$goods['id']}">
                                <button class="cut_num">-</button>
                                <input type="number" value="0" class="num shownum" {if $goods['is_use_buy_num_limit'] == '1'}max="{$goods['maxbuy']}"{/if}>
                                <button class="add_num">+</button>
                            </div>
                            
                        </div>
                    </div>
                </div>
                <!-- {if $goods['is_use_identity_detail'] == 1}
                <div class="">{$goods['identity_detail']}</div>
                {/if} -->
                {/loop}
                <div id="msg_box" style="display:none;"><div id="msg"></div></div>
                <script>
                    // total_num
                    // buybtn
                    $(function() {
                        
                        function numKey(key,num,money,id) {//判断只能存在一个
                            $('#total').text(" " +num+ " " );
                            $('.total_num').text(" " +parseInt(num)*parseFloat(money)+ " ");
                            $('.sureorder').attr('href', "{php echo mobileUrl('identity/order/sureorder')}&id="+id+"&total="+num);
                            $('.number').each(function (i,el) {
                                if(key!==i){
                                    $(this).find('input[type="number"]').val(0);
                                }
                            })
                        }
                        $('.add_num').each(function(i,el) {//数字加
                            $(this).click(function(){
                                var num = $(this).siblings('input[type="number"]'),
                                    moneyNum = $(this).parents('.number').data('num');
                                    goodsid = $(this).parents('.number').data('goodsid');
                                    maxnum = $(this).siblings('input[type="number"]').attr('max');
                                    console.log(maxnum);
                                if(parseInt(num.val())==maxnum && maxnum > 0){
                                    $('#msg').html('该商品一次最多购买<span style="color:red"> '+maxnum+' </span>件');
                                    $('#msg_box').attr('style', 'display:block;');

                                    setTimeout(function(){
                                        $('#msg_box').attr('style', 'display:none;');
                                    },1000);
                                }else{
                                    num.val(parseInt(num.val())+1);
                                    numKey(i,num.val(),moneyNum,goodsid);
                                }

                            })
                        })
                        $('.cut_num').each(function(i,el) {//数字减
                            $(this).click(function() {
                                var num = $(this).siblings('input[type="number"]'),
                                    moneyNum = $(this).parents('.number').data('num');
                                    goodsid = $(this).parents('.number').data('goodsid');
                                num.val(parseInt(num.val())===0 ? 0 :parseInt(num.val())-1);
                                numKey(i,num.val(),moneyNum,goodsid);
                            })
                        })
                    })

                </script>
        </div>

        {if !empty($stores)}
        <script language='javascript' src='https://api.map.baidu.com/api?v=2.0&ak=ZQiFErjQB7inrGpx27M1GR5w3TxZ64k7&s=1'></script>
        <div class='fui-according-group'>
            <div class='fui-according'>
                <div class='fui-according-header'>
                    <i class='icon icon-shop'></i>
                    <span class="text">适用门店</span>
                    <span class="remark"><div class="badge">{php echo count($stores)}</div></span>
                </div>
                <div class="fui-according-content store-container">
                    {loop $stores $item}
                    <div  class="fui-list store-item"

                          data-lng="{php echo floatval($item['lng'])}"
                          data-lat="{php echo floatval($item['lat'])}">
                        <div class="fui-list-media">
                            <i class='icon icon-shop'></i>
                        </div>
                        <div class="fui-list-inner store-inner">
                            <div class="title"> <span class='storename'>{$item['storename']}</span></div>
                            <div class="text">
                                <span class='realname'>{$item['realname']}</span> <span class='mobile'>{$item['mobile']}</span>
                            </div>
                            <div class="text">
                                <span class='address'>{$item['address']}</span>
                            </div>
                            <div class="text location" style="color:green;display:none">正在计算距离...</div>
                        </div>
                        <div class="fui-list-angle ">
                            {if !empty($item['tel'])}<a href="tel:{$item['tel']}" class='external '><i class=' icon icon-phone' style='color:green'></i></a>{/if}
                            <a href="{php echo mobileUrl('store/map',array('id'=>$item['id']))}" class='external' ><i class='icon icon-location' style='color:#f90'></i></a>
                        </div>
                    </div>
                    {/loop}
                </div>

                <div id="nearStore" style="display:none">

                    <div class='fui-list store-item'  id='nearStoreHtml'></div>
                </div>
            </div></div>
        {/if}

        <div class='fui-cell-group price-cell-group'>
            <div class="fui-cell" style="height:40px;">
                <div class="fui-cell-label">商品小计</div>
                <div class="fui-cell-info"></div>
                <div class="fui-cell-remark noremark">共<span id="total">0</span>件商品 合计 : &yen; <span class="total_num">0</span> </div>
            </div>
            {if $goods['goodstype']==0 && $goods['type']==0 && $goods['isverify']==0}
            <div class="fui-cell">
                <div class="fui-cell-label">运费</div>
                <div class="fui-cell-info"></div>
                <div class="fui-cell-remark noremark dispatchprice">
                    {if is_array($goods['dispatch'])}
                        &yen;{php echo number_format($goods['dispatch']['min'],2)} ~ &yen;{php echo number_format($goods['dispatch']['max'],2)}
                    {else}
                        {php echo $goods['dispatch'] == 0 ? '包邮' : '&yen;'.number_format($goods['dispatch'],2)}
                    {/if}
                </div>
            </div>
            {/if}
            
            
        </div>
    </div>

    

    <div class='fui-footer fui-navbar order-create-checkout'>
        <p class="nav-item" style="width:10%;text-align: left;padding:0.3rem;font-size:0.7rem;">
            需付 {if $goods['isverify'] == 0 && $goods['goodstype']==0 && $goods['type']==0 && $goods['dispatch'] > 0}(含运费){/if}： &yen;<span class="total_num">0</span>
        </p>
        
        <!-- <a href="javascript:;" class="nav-item btn btn-danger buybtn" id="openActionSheet">立即支付</a> -->
        <a href="{php echo mobileUrl('identity/order/sureorder', array('id' => 0, 'total' => 0))}" class="nav-item btn btn-danger sureorder" >确认订单</a>
        <!-- http://mp.test.weihaima.com/app/index.php?i=11005&c=entry&m=ewei_shopv2&do=mobile&r=order.create&id=5&optionid=0&total=1&giftid&liveid=0 -->
    </div>
    {template 'order/pay/wechat_jie'}
    <script language='javascript'>
        window.onload = require(['biz/order/create'], function (modal) {modal.init({php echo json_encode($createInfo)}); });
    </script>
    
    
</div>
{template '_footer'}
<!--913702023503242914-->